﻿
@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<script src="~/Content/js/js3city.js"></script>
<div class="user-order-box">
    <div class="user-order">
        <div class="home-location-box">
            <div class="goods-location">
                <i><img src=" ~/Content/images/icon/home.png" alt="" width="18" height="18"></i>
                <span><a href="">首页</a></span>
                <span>></span>
                <span><a href="">订单管理</a></span>

            </div>


        </div>

        <div class="user-order-main">
            <!--个人中心左侧栏目-->
            <div class="home-box-left">
                <ul>
                    <h3><i><img src=" ~/Content/images/icon/user-products.png" width="18" alt="18"></i>&nbsp;订单中心</h3>
                    <li><a href="~/Shopping/Index">我的购物车</a></li>
                    <li><a href="~/Order/Index1">订单管理</a></li>

                </ul>

                <ul>
                    <h3><i><img src=" ~/Content/images/icon/us.png" width="18" alt="18"></i>&nbsp;会员中心</h3>
                    <li><a href="~/User/Index">个人信息</a></li>
                    <li><a href="~/Address/Index">收货地址</a></li>
                </ul>
            </div>
            <!--个人中心左侧栏目end!-->

            <div class="user-cart-box">
                <div class="user-cart-main">
                    <!--通用DIV-->
                    <div class="order-manager-title">
                        <a href="" id="orderbtn" class="active">我的地址</a>
                        <a href="" class="voidbtn">新增地址</a>
                    </div>
                    <!--通用DIV end-->
                    <!--我的地址列表-->

                    <div class="user-money-box" id="tb1">

                        <div class="money-list">
                            <span>我的地址列表</span>
                            <br />
                            <table width="1050" border="1" cellpadding="0" cellspacing="0" bordercolor="#d5d5d5">
                                <tr bgcolor="#eeeeee" align="center">
                                    <td height="30" width="100">收货人</td>
                                    <td>所在地区</td>
                                    <td width="250">街道地址</td>
                                    <td>电话/手机</td>
                                    <td width="150">创建时间</td>
                                    <td>操作</td>
                                </tr>
                                @{
                                    foreach (var item in Model)
                                    {
                                        <tr align="center">
                                            <td height="40">@item.Nam</td>
                                            <td>@item.Province@item.City</td>
                                            <td>@item.Information</td>
                                            <td>@item.Phone</td>
                                            <td>@item.CreateTime</td>
                                            <td><a href="/Address/Update/@item.Id">修改</a> | <a class="IsDefault" data-id="@item.Id">设置为默认地址</a> | <a class="Delete" data-id="@item.Id">删除</a></td>
                                        </tr>
                                    }

                                }
                            </table>

                        </div>

                        <!--order-page-->
                        <div class="order-page">

                            <table width="400" border="0">
                                <tr>
                                    <td width="82" align="right"><a href="" class="order-page-up"><<</a></td>
                                    <td width="235">
                                        <ul>
                                            <li><a href="">1</a></li>
                                            <li><a href="">2</a></li>
                                            <li><a href="">3</a></li>
                                            <li><a href="">4</a></li>
                                            <li><a href="">5</a></li>
                                        </ul>
                                    </td>
                                    <td width="109" align="left"><a href="" class="order-page-down">>></a></td>
                                </tr>
                            </table>
                        </div>
                        <!--order-page end!-->




                    </div>

                    <!--我的地址end!-->
                    <!--新增地址-->
                    <div class="user-addr-box" id="tb2">

                        <div class="user-addr">
                            <span>新增地址</span>

                            <div class="user-addr2">
                                <table width="1050" border="0" cellpadding="0" cellspacing="0">
                                    <tr>
                                        <td width="100" align="center">收货人：</td>
                                        <td>
                                            <label>
                                                <input type="text" id="Nam" name="textfield" class="user-addr-text" />
                                            </label>
                                        </td>
                                    </tr>
                                </table>
                            </div>

                            <div class="user-addr2">
                                <table width="1050" border="0" cellpadding="0" cellspacing="0">
                                    <tr>
                                        <td width="100" align="center">所在区域：</td>
                                        <td>
                                            <select name="sheng" class="user-state-select" id="shen">
                                            </select>
                                            <select name="shi" class="user-state-select" id="city">
                                            </select>
                                            <select name="xian" class="user-state-select" id="xian">
                                            </select>
                                        </td>
                                    </tr>
                                </table>
                            </div>

                            <div class="user-addr2">
                                <table width="1050" border="0" cellpadding="0" cellspacing="0">
                                    <tr>
                                        <td width="100" align="center">街道地址：</td>
                                        <td>
                                            <label>
                                                <textarea name="textarea" id="Information"></textarea>
                                            </label>
                                        </td>
                                    </tr>
                                </table>
                            </div>

                            <div class="user-addr2">
                                <table width="1050" border="0" cellpadding="0" cellspacing="0">
                                    <tr>
                                        <td width="100" align="center">手机号码：</td>
                                        <td>
                                            <label>
                                                <input type="text" name="textfield" id="Phone" class="user-addr-text" />
                                            </label>
                                        </td>
                                    </tr>
                                </table>
                            </div>

                            <div class="user-addr2">
                                <table width="1050" border="0" cellpadding="0" cellspacing="0">
                                    <tr>
                                        <td width="150" align="center">是否为默认地址：</td>
                                        <td>
                                            <label>
                                                <label><input type="radio" name="d_name" value="是"> 是</label>
                                                &nbsp;<label><input type="radio" name="d_name" value="否"> 否</label>
                                            </label>
                                        </td>
                                    </tr>
                                </table>
                            </div>
                            <div class="user-addr2">

                                <button id="btn" class="user-addr-btn">保存添加</button>

                            </div>
                            <input type="hidden" id="CustId" value="@ViewBag.b" />

                            <input type="hidden" id="CreateTime" />
                        </div>

                    </div>

                    <!--新增地址end!-->


                </div>

            </div>

        </div>

    </div>
    <!--回收站列表end!-->


</div>
<script type="text/javascript">
    $("#orderbtn").click(function () {
        $("#tb1").show();
        $("#tb2").hide();
    });
    $(".voidbtn").click(function () {
        $("#tb2").show();
        $("#tb1").hide();

    });

    /*点击标签，背景色改变*/
    $('.order-manager-title a').on('click', function (e) {
        event.preventDefault();
        $(this).css('background', '#363636').siblings().css('background', '#f5a700');

    });


</script>

<!--省市县三级联动js-->
<script type="text/javascript">
    addressInit('shen', 'city', 'xian', '请选择省', '请选择市', '请选择县');
</script>

<script>
    //获取input元素
    var _input = document.getElementById('CreateTime');

    var date = new Date();
    var seperator = "/";
    var year = date.getFullYear();
    var month = date.getMonth() + 1;
    var strDate = date.getDate();
    if (month >= 1 && month <= 9) {
        month = "0" + month;
    }
    if (strDate >= 0 && strDate <= 9) {
        strDate = "0" + strDate;
    }
    var currentDate = year + seperator + month + seperator + strDate; //当前日期

    _input.value = currentDate; //赋值给input.value
    _input.setAttribute('disabled', 'disabled'); //不可编辑
</script>



<script>
    //添加
    $("#btn").click(function () {
        var Nam = $("#Nam").val();
        var Province = $("#shen").val();
        var City = $("#city").val();
        var District = $("#xian").val();
        var Information = $("#Information").val();
        var Phone = $("#Phone").val();
        var IsDefault = $('input[name="d_name"]:checked').val();
        var CustId = $("#CustId").val()
        var CreateTime = $("#CreateTime").val()
        $.post("/Address/Add", {
            Nam: Nam,
            Province: Province,
            City: City,
            District: District,
            Information: Information,
            Phone: Phone,
            IsDefault: IsDefault,
            CustId: CustId,
            CreateTime: CreateTime
        }, function (res) {
            if (res.Success) {
                alert(res.Message)
                window.location.href = "/Address/Index"
            } else {
                alert(res.Message)
            }

        })
    });
    //设置默认地址
    $(".IsDefault").click(function () {
        var id = $(this).data("id");
        var _this = this;
        $.post("/Address/SetMR", { Id: id }, function (res) {
            if (res.Success) {
                alert(res.Message)
                window.location.href = "/Address/Index"
            } else {
                alert(res.Message)
            }
        })

    });
    //删除
    $(".Delete").click(function () {
        var id = $(this).data("id");
        var _this = this;
        $.post("/Address/Delete", { Id: id }, function (res) {
            if (res.Success) {
                alert(res.Message)
                window.location.href = "/Address/Index"
            } else {
                alert(res.Message)
            }
        })

    });


</script>



